<template>
  <view class="item">
    <view class="left">
      <radio v-if="isShow" :checked="item.goods_status" @click="radioClick"></radio>
      <image :src="item.goods_small_logo || defaultImg" mode=""></image>
    </view>
    <view class="right">
      <view class="info">
        {{item.goods_name}}
      </view>
      <!-- <view>{{total}}</view> -->
      <view class="price">
        <text>￥{{item.goods_price | formatMoney}}元</text>
        <uni-number-box v-if="isShow" v-model="item.goods_count" :min="1" @change="changeCount"></uni-number-box>
      </view>
    </view>
  </view>
</template>

<script>
  import {
    mapGetters
  } from 'vuex'
  export default {
    name: "my-goods",
    props: {
      item: {
        type: Object
      },
      isShow: {
        type: Boolean,
        default: false
      }
    },
    computed: {
      ...mapGetters('cart', ['total'])
    },
    filters: {
      formatMoney(num) {
        return num.toFixed(2)
      }
    },
    data() {
      return {
        defaultImg: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png',
      };
    },
    methods: {
      radioClick() {
        this.$emit('changeEvent', this.item.goods_id)
      },
      changeCount(e) {
        console.log(e);
        this.$emit('changeCount', {
          goods_id: this.item.goods_id,
          goods_count: e
        })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .item {
    display: flex;
    padding: 20rpx;
    font-size: 12px;
    border-bottom: 1px solid #f8f7f7;

    .left {
      display: flex;
      align-items: center;

      image {
        width: 200rpx;
        height: 200rpx;
        margin-right: 20rpx;
      }
    }

    .right {
      display: flex;
      flex-direction: column;
      justify-content: space-between;

      .price {
        display: flex;
        justify-content: space-between;
        align-items: center;

        text {
          color: #c00000;
          font-size: 16px;
        }
      }
    }
  }
</style>